﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PencilSketch
{
    public partial class Form1 : Form
    {
        private string path = @"sketchimage.exe";
        public Form1()
        {
            InitializeComponent();
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
           OpenFileDialog dlg=new OpenFileDialog();
            dlg.Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif|BMP Files(*.bmp)|*.bmp|All Files|*.*";
            dlg.CheckFileExists = true;
            dlg.Multiselect = false;
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                txtPath.Text = dlg.FileName;
            }
        }

        private void btnLoad_Click(object sender, EventArgs e)
        {
            if (File.Exists(txtPath.Text))
            {
                pbImage.Image = Image.FromFile(txtPath.Text);
                btnCreate.Enabled = true;
                

            }
            else
            {
                MessageBox.Show("Invalid Path");
            }

        }

        private void btnCreate_Click(object sender, EventArgs e)
        {
            File.Delete("PencilSkech.jpg");
            Process proc = Process.Start(path, txtPath.Text);
            System.Threading.Thread.Sleep(2000);
            
            pbImage.Image = Image.FromFile(@"PencilSketch.jpg");
            btnSave.Enabled = true;
            btnCreate.Enabled = false;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            SaveFileDialog dlg=new SaveFileDialog();
            dlg.Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif|BMP Files(*.bmp)|*.bmp|All Files|*.*";
            dlg.CheckPathExists = true;
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                
                pbImage.Image.Save(dlg.FileName);
               
            }
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            
        }
    }
}
